using HCore.IOC.Beans.Factory;
using HCore.IOC.Beans.Factory.Attribute.Attr;
using HCore.IOC.Context.Event;
using JetBrains.Annotations;

namespace Session
{
    public abstract class SessionProvider<T> : EventPublisher, IInitializingBean where T : ISession
    {
        [Autowired] private SessionService mSessionService;
        [CanBeNull] protected T Session;

        public void AfterPropertiesSet()
        {
            mSessionService.AddNewGameStartBeforeEvent(session =>
            {
                Session = OnSetSession(session);
                OnPostSetSession();
            });
        }

        protected virtual T OnSetSession(ISession session)
        {
            return (T)session;
        }

        protected virtual void OnPostSetSession()
        {
        }
    }

    public abstract class SessionProvider : SessionProvider<ISession>
    {
    }
}